package com.weilive.core.database;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicDataSource extends AbstractRoutingDataSource {

	private static final String ADMIN_DB = "admin_db";
	private static final String MIMICAM_DB = "mimicam_db";
	private static final String VIDEO_DB = "mimicam_vdo";
	private static final ThreadLocal<String> dataSourceKey = new ThreadLocal<String>();

	@Override
	protected Object determineCurrentLookupKey() {
		return dataSourceKey.get();
	}

	public static void setMimicam() {
		dataSourceKey.set(MIMICAM_DB);
	}

	public static void setVideo() {
		dataSourceKey.set(VIDEO_DB);
	}

	public static void clear() {
		dataSourceKey.set(null);
	}
}
